/** TTRiangle class
 *  Allows for creation of the triangle objects based on 3 points.
 * extends the TShape class.
 */
package button_tools;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

public class TTriangle extends TShape
{
    Point2D p1, p2, p3;
    
    // Constructor, takes a color and 3 Point2Ds representing our points
    public TTriangle(Color c, Point2D p1, Point2D p2, Point2D p3) {
        super(c, p1, p2, p3); // actually this doesnt matter, but its required.
        this.setType(TShape.SHAPE_TYPE.TRIANGLE);
        this.p1 = p1;
        this.p2 = p2;
        this.p3 = p3;
    }

    // the triangle drawing function requires three lines to connect all of the points
    @Override
    protected void draw(Graphics2D g2d) {
        g2d.setColor(m_Color);
        g2d.draw(new Line2D.Double(p1.getX(), p1.getY(), p2.getX(),p2.getY()));
        g2d.draw(new Line2D.Double(p2.getX(), p2.getY(), p3.getX(),p3.getY()));
        g2d.draw(new Line2D.Double(p3.getX(), p3.getY(), p1.getX(),p1.getY()));   
    }
   
    // get the points
    public Point2D[] getPoints() {
        Point2D[] parray = new Point2D[3];
        parray[0] = p1;
        parray[1] = p2;
        parray[2] = p3;

        return parray;
    }
    
    // get the RGB value of color.
    public int getColor() {
        return m_Color.getRGB();
    }
}
